package com.ahcfl.service.impl;

import com.ahcfl.dao.UserMapper;
import com.ahcfl.dto.PageBean;
import com.ahcfl.pojo.User;
import com.ahcfl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public PageBean<User> findUserByPageAndName(int pageNum, int pageSize, String name) {

        int total = userMapper.findTotalUserByPageAndUsername(name);

        int start = (pageNum-1)*pageSize;
        List<User> list = userMapper.findUserByPageAndUsername(start, pageSize, name);

        PageBean<User> pageBean = new PageBean<>(list,total);

        return pageBean;
    }

    @Override
    public boolean save(User user) {
        int num = userMapper.save(user);
        return num==1;
    }

    @Override
    public boolean deleteUserById(int id) {
        return userMapper.deteleUserById(id)==1;
    }

    @Override
    public boolean updateUser(User user) {

        return userMapper.updateUser(user)==1;
    }
}
